/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package tools;

import java.sql.Connection;
import java.sql.PreparedStatement;

import java.sql.SQLException;

import oracle.jdbc.pool.OracleDataSource;

/**
 *
 * @author w7
 */
public class koneksi {


//
// pilih koneksi yang sesuai
//    static String jdbcURL = "jdbc:oracle:thin:@localhost:1521:XE";
//    static String user = "spp";
//    static String password = "spp";
//    static Connection connection;
    
    static String jdbcURL = "jdbc:oracle:thin:@172.23.9.185:1521:orcl";
    static String user = "MHS105314091";
    static String password = "MHS105314091";
    static Connection connection;
////



    public koneksi() {
    }

    public static Connection getDBConnection() throws SQLException {

        try {
            OracleDataSource ds;
            ds = new OracleDataSource();

            ds.setURL(jdbcURL);
            connection = (Connection) ds.getConnection(user, password);
            System.out.println("Koneksi berhasil");
            return connection;
        } catch (SQLException ex) {
            System.out.println("Koneksi gagal");
            return null;
        }
    }

    public void close() {
        try {
            connection.close();
        } catch (SQLException ex) {
            System.out.println("Tidak bisa tutup kembali");
        }
    }

    public static void main(String[] args) throws SQLException {
        koneksi conn = new koneksi();
        koneksi.getDBConnection();
        conn.close();

    }
}
